package com.cell.api.application.netty.utils;

import com.cell.api.application.netty.code.Packet;
import com.cell.api.application.netty.handler.base.HandlerFactory;
import com.cell.api.application.netty.handler.base.IBaseHandler;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * Handler测试
 * </p>
 *
 * @author zdy
 * @date 2021/11/10
 */
@Slf4j
public class HandlerTest {

    private static final String DEVICE_STATUS_RES = "aabb030c000600ffff190002fe01000000";


    public static void main(String[] args) throws Exception {
        byte[] bytes = ByteBufUtil.decodeHexDump(DEVICE_STATUS_RES);
        ByteBuf byteBufCopy = Unpooled.copiedBuffer(bytes);
        Packet packet = CoderUtils.decode(byteBufCopy);
        IBaseHandler handler = HandlerFactory.createHandler(packet.getGetCommand());
        if (handler == null) {
            log.error("找不到对应的handler,指令：{}", packet.getGetCommand());
            return;
        }
        handler.doRequest(packet.getDataLength(), packet.getBytes());
    }
}
